package com.kantboot.system.user.role.repository;

import com.kantboot.system.user.role.domain.entity.SysUserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface SysUserRoleRepository extends JpaRepository<SysUserRole, Long> {

    /**
     * 根据角色编码删除
     */
    @Modifying
    @Transactional
    @Query("""
    DELETE FROM SysUserRole WHERE roleCode = :roleCode
    """)
    void deleteByRoleCode(@Param("roleCode") String roleCode);

    /**
     * 根据角色编码加用户ID删除
     */
    @Modifying
    @Transactional
    @Query("""
    DELETE FROM SysUserRole WHERE roleCode = :roleCode AND userId = :userId
    """)
    void deleteByRoleCodeAndUserId(@Param("roleCode") String roleCode, @Param("userId") Long userId);
}
